/**
 *
 */
package com.wilmar.process.web.taglibs;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

/**
 * @author 周立波 E-mail: zhoulibo_java@msn.cn
 * @version 1.0 日期2009-8-5 时间03:21:18
 */
public class ProcessTextAreaTag extends ProcessTagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1438272152898251858L;

	private String rows;
	private String cols;
	private String title;
	private String value;

	public int doEndTag() throws JspException {
		StringBuffer html = new StringBuffer();
		html.append("</textarea></fieldset>");
		JspWriter outer = this.pageContext.getOut();
		try {
			outer.write(html.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	/**
	 * @see org.springframework.web.servlet.tags.RequestContextAwareTag#doStartTagInternal()
	 */
	protected int doStartTagInternal() throws Exception {
		String value_ = "";
		String rows_ = "";
		String cols_ = "";
		
		if (this.value != null && this.value.trim().length() != 0) {
			value_ = this.value;
		}else if (super.getName() != null
				&& super.getName().trim().length() != 0) {
			value_ = super.getAttribute(super.getName());
		} 
		
		rows_ = this.rows;
		cols_ = this.cols;
		StringBuffer html = new StringBuffer();
		if (this.title == null)
			this.title = "";
		html.append("<fieldset><legend>" + this.title + "</legend>");
		html.append("<textarea rows=\"");
		html.append(rows_);
		html.append("\"");
		html.append(" cols=\"");
		html.append(cols_);
		html.append("\"");
		if (this.getName() != null) {
			html.append(" name=\"");
			html.append(this.getName());
			html.append("\" ");
		}
		if (this.getId() != null) {
			html.append(" id=\"");
			html.append(this.getId());
			html.append("\" ");
		}
		if (this.getCssStyle() != null) {
			html.append(" style=\"");
			html.append(this.getCssStyle());
			html.append("\"");
		}
		if (this.getCssClass() != null) {
			html.append(" class=\"");
			html.append(this.getCssClass());
			html.append("\"");
		}
		if (this.getReadonly() != null) {
			html.append(" readonly=\"");
			html.append("readonly");
			html.append("\"");
		}
		html.append(">");
		html.append(value_);
		JspWriter outer = this.getOut();
		try {
			outer.write(html.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	public void setCols(String cols) {
		this.cols = cols;
	}

	public void setRows(String rows) {
		this.rows = rows;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

}
